package de.jmda.gen.java.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.ParameterGenerator;
import de.jmda.gen.java.ParametersGenerator;


/**
 * Maintains a list of {@link ParameterGenerator}s.
 *
 * @author rwegner
 */
public class DefaultParametersGenerator
		extends AbstractCompoundGenerator
		implements ParametersGenerator
{
	private List<ParameterGenerator> parameterGenerators;

	public DefaultParametersGenerator()
  {
	  this(new ArrayList<ParameterGenerator>());

	  setComponentSeparator(", ");
  }

	public DefaultParametersGenerator(List<ParameterGenerator> generators)
  {
	  super();
	  
	  setParameterGenerators(generators);
  }

	/**
	 * @return collection of <code>Generator</code>s with the return values of the
	 *         following methods in the following order:
	 *         <ul>
	 *           <li>{@link #getParameterGenerators()}</li>
	 *         </ul>
	 * 
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
  public List<Generator> getGeneratorComponents()
  {
		// copy specific generators to non-specific generators and make Java happy
		List<Generator> result = new ArrayList<Generator>();

		Collection<ParameterGenerator> generators = getParameterGenerators();
		
		if (generators != null)
		{
			result.addAll(generators);
		}

		return result;
  }

	/**
	 * @see de.jmda.gen.java.ParametersGenerator#getParameterGenerators()
	 */
	@Override
  public List<ParameterGenerator> getParameterGenerators()
  {
		return parameterGenerators;
  }

	public void setParameterGenerators(List<ParameterGenerator> generators)
  {
		if (generators == null)
		{
			return;
		}

		this.parameterGenerators = generators;
  }

	/**
	 * Convenience method to add an <code>ParameterGenerator</code> to
	 * {@link #getParameterGenerators()}.
	 *
	 * @param parameterGenerator
	 */
	public void add(ParameterGenerator parameterGenerator)
	{
		getParameterGenerators().add(parameterGenerator);
	}
}